<template>
	<view class="loginP">

		<div style="position: absolute;opacity: 0;" @dblclick="goHome">12312312312</div>

		<view class="mainTitle">欢迎来到赢厚火星</view>

		<!-- <view class="classesifyP">
      <view class="classesify">
		  
        <view :class="selectIfy==1?'classesify-puc':'classesify-pucs' "  @click="pucM" >代理</view>
        <!-- <view class="classesify-pucs" @click="pucM" v-else>代理12</view> -->
		<!-- 
        <view class="classesify-bus" @click="busM" v-if="selectIfy === 1">商户</view>
         <view class="classesify-buss"  @click="busM" v-else>商户</view>
      </view>
    </view> -->
		<view class="user-pwd">

			<view class="userP">
				<image :style="{ width:'1.3rem',height:'1.4rem' }" src="../../style/image/login/A6.png" alt="">
					<view class="inputC">
						<!-- <input  v-model="userInput"   type="text" placeholder="账号" > -->
						<u-input :clearable='true' v-model="userInput" type="text" placeholder="账号" />
					</view>
					<!-- <image style=" width: 1rem;height: 1rem;" class="rightIcon"  src="../../style/image/login/A3.png" alt="">    -->
			</view>

			<view class="pwdP">
				<image :style="{ width:'1.3rem',height:'1.4rem'}" src="../../style/image/login/A2.png" alt="">
					<view class="inputC">
						<u-input v-model="pwdInput" :type="passwordType" placeholder="密码" />
						<!-- <input  v-model="pwdInput" style="border-style:none" :type="passwordType" > -->
					</view>
					<!-- <image @click="pwdM" style="width: 1.4rem; height: 0.8rem;border-style:none" v-if="passwordType=='password' "   class="rightIcon" src="../../style/image/login/A4.png" alt="">
             <image  @click="pwdM" v-else style=" width: 1.4rem; height: 0.8rem;"  class="rightIcon" src="../../style/image/login/hidden.png" alt="">
         -->
			</view>

		</view>

		<view class="loginBtnP" @click="loginM" style="padding: 2rem 0 1rem 0;">
			<view class="loginBtn">
				登陆
			</view>
		</view>

		<view class="forgot-register">
			<view @click="goforGotP" class="forgot">
				忘记密码
			</view>
			<view class="register" @click="goRegister">
				注册账号
			</view>
		</view>


		<u-toast ref="uToast" />

		<!-- <view>123321321321312321--test----{{msg}}</view>
            <view>123321321321312321--test----{{test1}}</view>
            <view>123321321321312321--test----{{msgC}}</view> -->
		<!-- <u-button type="error">危险按钮</u-button>
            <view>
             子组件：我的子组件的数据 <button @click="childPropMsg">小——》大点击给父组件发送数据</button>
            </view> -->
	</view>
</template>

<script lang='ts'>
	import {
		Component,
		Prop,
		Vue,
		Watch,
		Emit
	} from "vue-property-decorator";
	import uField from "@/uview-ui//components/u-field/u-field.vue";

	import uInput from "../../uview-ui/components/u-input/u-input.vue";
	import {
		globalModule
	} from '../../utils/uniRequest';
	import {
		loginCDB
	} from "../../utils/uniApi";

	@Component({
		//   @Component  是一个装修器   不可以在下面写语句
		name: "test",
		components: {
			'u-input': uInput
		}
		//         filters:{
		//     Test(arg: string){
		//       return arg + "  我来刷点存在感"
		//     }
		//   },
		//   directives:{
		//     Test(arg: string){
		//       return arg + "  我来刷点存在感"
		//     }
		//   }
	})
	export default class extends Vue {
		// props: ['postTitle'],

		@Prop({
			type: String, // 父组件传递给子组件的数据类型
			required: false, // 是否必填
			default: " ", // 默认值， 如果传入的是 Object，则要 default: ()=>({}) 参数为函数
		})
		msg!: string;

		public userInput = uni.getStorageSync("allData").phone;
		public pwdInput = uni.getStorageSync("allData").pwd;
		public verifyInput = ''
		passwordType = "password";

		childMsg: string = "自组件的数据";
		selectIfy: any = 1;

		//test:string=msg
		test1: string = "eqweqweqweqw";

		msgC: string = "子组件的msgC数据";


		public clientid = ''


		public porxyShop = ''

		created() {
			console.log("888123123123123123自组件");
			console.log("999", this);
			console.log("父组件传递的参数:", this.$props.msg); // one
		}

		mounted() {
			//  console.log('父组件传递的参数:',this.$parent)   //暂时不考虑

			this.getClientId()

			console.log(this.getClientId())
			
		}

		onShow() {
			// console.log(uni.getStorageSync("allData").phone, 'phooone')
			
		}


		getClientId() {
			//获取客户端ID和版本号
			var clientid: any = '';
			// // #ifdef APP-PLUS
			// // 苹果系统
			// plus.device.getInfo({
			// 	success: function(e:any) {
			// 		clientid = e.uuid;
			// 		uni.setStorageSync('clientid', clientid);
			// 	},
			// 	fail: function(e:any) {
			// 		console.log(e);
			// 	}
			// });
			// // 安卓系统
			(plus as any).device.getAAID({
				success: function(e: any) {
					clientid = e.aaid;
					console.log(clientid, 'clientid');
					uni.setStorageSync('clientid', clientid);
				},
				fail: function(e: any) {
					console.log(e);
				}
			});
			//老版本、安卓模拟器
			if (clientid == '') {
				clientid = plus.device.uuid;
				uni.setStorageSync('clientid', clientid);
			}
			// #endif

			this.clientid = clientid
			return clientid;
		}

		loginM1() {
			console.log(this.selectIfy, '999')
		}

		goHome() {
			uni.switchTab({
				//存储好后跳转页面
				url: "../home/home",
			});

		}

		loginM() {
			uni.clearStorageSync()
			let params = {
				oid: globalModule.oid, //
				phone: this.userInput, //13627111557
				password: this.pwdInput,
				clientid: uni.getStorageSync('clientid'),
				loginStatus: this.selectIfy == 1 ? 'porxy' : 'shop', //   登录平台（porxy ：代理端，shop：商户端）
			};

			if (this.selectIfy == 1) {
				this.porxyShop = 'porxy'
			} else {
				this.porxyShop = 'shop'
			}

			loginCDB(params).then((res: any) => {

				console.log(res.data, '+++数据+++')



				if (res.data.message == '登录成功') {
					uni.setStorage({
						key: "allData",
						data: res.data.data,
						success: function() {

							setTimeout(() => {
								console.log(uni.getStorageSync("allData"), 'allData++---')
							}, 800)

						},
					});
					(this.$refs.uToast as any).show({
						title: res.data.message,
						type: 'success',
					})

					console.log(res, '登陆返回数据', uni.getStorageSync("account"))


					if (uni.getStorageSync("account") == null || uni.getStorageSync("account") == undefined || uni.getStorageSync(
							"account") == '' || uni.getStorageSync("account").length == 0) {
						console.log('第一次')

						let accountList = []

						let obj = {
							id: res.data.data.id,
							userId: res.data.data.id,
							card: res.data.data.card,
							nickName: res.data.data.nickName,
							headImg: res.data.data.headImg,
							phone: res.data.data.phone,
							recCode: res.data.data.recCode
						}

						accountList.push(obj)



						uni.setStorage({
							key: "account",
							data: accountList,
							success: function() {

								setTimeout(() => {
									console.log(uni.getStorageSync("account"), '12312321')
								}, 800)

							},
						});



					} else {
						console.log('第n次')
						let obj = {
							id: res.data.data.id,
							userId: res.data.data.id,
							card: res.data.data.card,
							nickName: res.data.data.nickName,
							headImg: res.data.data.headImg,
							phone: res.data.data.realName
						}

						console.log('第n次', obj, uni.getStorageSync("account"))

						var arr = uni.getStorageSync("account")
						arr.push(obj)
						console.log(arr, '第n次')

						uni.setStorage({
							key: "account",
							data: arr,
							success: function() {

								setTimeout(() => {
									console.log(uni.getStorageSync("account"), '12312321')
								}, 800)

							},
						});

					}


					uni.setStorage({
						key: "token",
						data: res.data.data.token,
						success: function() {

							setTimeout(() => {
								uni.switchTab({
									//存储好后跳转页面
									url: "../home/home",
								});

							}, 800)

						},
					});

					console.log(res.data.data.id, '8')
					uni.setStorage({
						key: "userId",
						data: res.data.data.id,
						success: function() {},
					});

					let obj = {
						supportStaffPhone: res.data.data.supportStaffPhone, //客服电话
						phone: res.data.data.phone,
						porxyShop: this.porxyShop,
						loginStatus: res.data.data.loginStatus,
						nickName: res.data.data.nickName,
						headImg: res.data.data.headImg,
						swiperImg: res.data.data.proxyHomeRollImgList,
						obrandConfig: res.data.data.obrandConfig,
					}

					console.log('otherDataotherData', obj)

					uni.setStorage({
						key: "otherData",
						data: obj,
						success: function() {
							console.log(uni.getStorageSync("otherData"), 'otherDataotherData123123')
						},
					});


					uni.setStorage({
						key: "userCard",
						data: res.data.data.card,
						success: function() {},
					});

				} else {

					(this.$refs.uToast as any)
					.show({
						title: res.data.message,
						type: "warning",
						// url: '/pages/user/index'
					});

				}




			});


		}

		pucM() {
			console.log(12312312);
			this.selectIfy = 1;
		}

		pwdM() {
			if (this.passwordType == "password") {
				this.passwordType = "text";
			} else if (this.passwordType == "text") {
				this.passwordType = "password";
			}
		}
		goRegister() {
			console.log(123);

			uni.navigateTo({
				url: "../register/recommend",
			});
		}
		goforGotP() {
			console.log(123);

			uni.navigateTo({
				url: "../forgotP/index",
			});
		}
		// busM=()=>{
		//    console.log(99999)

		//     this.selectIfy=2
		//     this.$forceUpdate()
		//  //  this.$set(this.selectIfy, 1,2)

		// //    window.reload()

		//     console.log(99999,this.selectIfy)
		// }
		busM() {
			//方法中获取this
			this.selectIfy = 2;
		}

		@Emit("bindSend") //@Emit()不传参数,那么它触发的事件名就是它所修饰的函数名.
		send(msgC: string) {
			//return 123      //如果没有返回值 那么传递的参数就是参数
		}

		childPropMsg() {
			//方法中获取this
			this.msgC = "子组件的msg数据,被传给了父组件";
			this.send(this.msgC);
		}

		@Watch("$route")
		routechange(to: any, from: any) {
			// if (to.query.name!=from.query.name) {
			// }
			console.log(to);
		}

		//         // dynamic component
		// 51   $refs!: {
		// 52     helloComponent: Hello
		// 53   }
	}
</script>

<style scoped>
	.loginP {
		padding: 2rem;
	}

	.mainTitle {
		text-align: center;
		font-size: 1.1rem;
		padding: 2rem 2rem 0 2rem;
	}

	.classesifyP {
		text-align: center;
		display: flex;
		justify-content: center;
	}

	.classesify {
		width: 11rem;
		height: 2.1875rem;
		border: 1px solid #02af74;

		display: flex;
		align-items: center;
		border-radius: 100px;
		/* //   background-color: red; */
	}

	.classesify-puc {
		width: 50%;
		font-size: 0.6rem;
		border-bottom-left-radius: 100px;
		border-top-left-radius: 100px;
		height: 100%;
		line-height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #02af74;
	}

	.classesify-pucs {
		width: 50%;
		font-size: 0.6rem;
		border-bottom-left-radius: 100px;
		border-top-left-radius: 100px;
		height: 100%;
		line-height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: white;
	}

	.classesify-bus {
		width: 50%;
	}

	.classesify-buss {
		width: 50%;
		font-size: 0.6rem;
		border-bottom-right-radius: 100px;
		border-top-right-radius: 100px;
		height: 100%;
		line-height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #02af74;
	}

	.userP {
		display: flex;
		align-items: center;
		margin: 4rem 0rem 1rem 0rem;
		padding: 0.3125rem 0rem;
		border-bottom: 1px solid #dfdfdf;
		/* // justify-content: space-between; */
	}

	.pwdP {
		display: flex;
		align-items: center;
		margin: 2rem 0rem 1rem 0rem;
		padding: 0.3125rem 0rem;
		border-bottom: 1px solid #dfdfdf;
		/* // justify-content: space-between; */
	}

	.inputC {
		width: 80%;
		padding-left: 1rem;
	}

	.rightIcon {
		margin: 0 auto;
	}

	.loginBtnP {
		width: 100%;
		display: flex;
		justify-content: center;
	}

	.loginBtn {
		width: 14rem;
		padding: 0.5rem;
		background-color: #02af74;
		border-radius: 0.5rem;
		color: white;
		text-align: center;
		font-size: 1.1rem;
	}

	.forgot-register {
		padding: 1rem 0rem;
		display: flex;
		justify-content: space-between;
		color: #747474;
	}

	.user-pwd {
		margin-bottom: 2rem;
	}
</style>
